<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/common/define"/>

<div class="pageContent">

	<form method="post" action="${path}/saveAction.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<div class="pageFormContent" layoutH="400">
			<fieldset>
				<dl >
					<dt>操作名称：</dt>
					<dd><input name="name" id="bean_name" type="text" size="30" value="${bean.name}" class="required" /></dd>
				</dl>
				<dl >
					<dt>视图名称：</dt>
					<dd><input name="viewName" type="text" size="30" value="${bean.viewName}" class="required" /></dd>
				</dl>
				<dl class="nowrap">
					<dt>描述：</dt>
					<dd><textarea name="description" cols="90" rows="4">${bean.description}</textarea></dd>
				</dl>
			</fieldset>
		</div>

		<div class="pageFormContent" layoutH="160">
		<div class="tabs">
			<div class="tabsHeader">
				<div class="tabsHeaderContent">
					<ul>
						<li class="selected"><a href="javascript:void(0)"><span>操作列表</span></a></li>
						<li><a href="javascript:void(0)"><span>返回值列表</span></a></li>
					</ul>
				</div>
			</div>
			<div class="tabsContent" style="height: 340px;">
				<div>
					<div class="panelBar">
						<ul class="toolBar">
							<li><a class="add" onclick="addunit('search','添加查询操作单元');" title="添加查询操作单元"><span>添加查询</span></a><br /><br /></li>
							<li class="line">line</li>
							<li><a class="add" onclick="addunit('update','添加更新操作单元');" title="添加更新操作单元"><span>添加更新</span></a><br /><br /></li>
							<li class="line">line</li>
							<li><a class="add" onclick="addunit('define','添加自定义操作单元');" title="添加自定义操作单元"><span>添加自定义</span></a><br /><br /></li>
							<li class="line">line</li>
							<li><a class="edit" onclick="modify2();" title="修改"><span>修改</span></a></li>
							<li class="line">line</li>
							<li><a class="delete" onclick="deleteunit();"><span>删除</span></a></li>
						</ul>
					</div>
					<table class="list nowrap" width="100%">
						<thead>
							<tr>
								<th type="text" name="items[#index#].itemString" width="80">操作单元名称</th>
								<th type="text" name="items[#index#].itemInt" width="240">操作单元描述</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${! empty bean.actionUnits}">
							<c:forEach var="data" items="${bean.actionUnits}">
							<tr target="params" rel="${data.name}" class="base_define_actionunit_list_tr">
								<td>${data.name}</td>
								<td>${data.description}</td>
							</tr>
							</c:forEach>
							</c:if>
						</tbody>
					</table>
				</div>
				<div>
					<table class="list nowrap itemDetail" addButton="添加参数" width="100%">
						<thead>
							<tr>
								<th type="text" name="items.key[#index#]" size="30" fieldClass="required">键名</th>
								<th type="text" name="items.value[#index#]" size="30" fieldClass="required">值</th>
								<th type="lookup" name="items[#index#].org.name" lookupGroup="items[#index#].org" 
								suggestUrl="..${ctx}/common/view.html?jsp=base/com/java_data_type_list" suggestFields="name" size="23" 
								fieldClass="required">数据类型</th>
								<th type="text" name="items.format[#index#]" size="30">格式</th>
								<th type="del" width="30">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${! empty bean.fields }">
							<c:forEach var="data" items="${bean.fields}" varStatus="status">
							<tr>
								<td>
									<input type="text" class="required textInput" size="30" value="${data.key}" name="items.key[${status.index}]" />
								</td>
								<td><input type="text" class="required textInput" size="30" value="${data.value}" name="items.value[${status.index}]" /></td>
								<td>
									<input type="hidden" name="items[${status.index}].org.id" value="${data.type}" />
									<input type="text" name="items[${status.index}].org.name"  size="23" lookuppk="id" 
									suggesturl="..${ctx}/common/view.html?jsp=base/com/java_data_type_list" class="required textInput" 
									lookupgroup="items[${status.index}].org" autocomplete="off" value="${data.typeString}" postfield="" suggestfields="name" />
								</td>
								<td><input type="text" class="textInput" size="30" value="${data.format}" name="items.format[${status.index}]" /></td>
								<td width="30"><a class="btnDel " href="javascript:void(0)">删除</a></td>
							</tr>
							</c:forEach>
							</c:if>			
						</tbody>
					</table>
				</div>
			</div>
			
			<div class="tabsFooter">
				<div class="tabsFooterContent"></div>
			</div>
		</div>

		</div>
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit" >保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			var url = "${path}/list.html";
			navTab.reload(url,null,"base_define_action_list");
			// navTab.reloadFlag("base_define_action_list");// 下次切换到列表页签时需要刷新一下
			setTimeout(function(){navTab.closeCurrentTab();}, 100);// 关闭此编辑页签
		}
	}
}

function addunit(action, title){
	var url = "${path}/addunit.html?state=sub&type=" + action + "&name=" + $('#bean_name').val();
	//alert(url);
	$.pdialog.open(url, "base_define_add_unit", title,{width:800,height:460,mask:true,maxable:false,resizable:false});
}

/**
 * 此方法如果也使用与list.jsp文件的“modify”方法同名，就会出现冲突。
 */
function modify2(){
	var rel = '';
	$('.base_define_actionunit_list_tr').each(function(){
		// alert($(this).attr('rel'));
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		var url = "${path}/getUnit.html?name=" + rel;
		var title = "更新操作单元";
		$.pdialog.open(url, "base_define_modify_unit", title,{width:800,height:460,mask:true,maxable:false,resizable:false});
	}
}

function deleteunit(){
	var rel = '';
	$('.base_define_actionunit_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var url = "${path}/delete.html?type=unit&id=" + rel;
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/getAction.html?name=" + $('#bean_name').val();
						navTab.reload(url);
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}
</script>
